package com.thalesgroup.preferenceFramework.algorithms;

import com.thalesgroup.graphFramework.core.Graph;
import com.thalesgroup.graphFramework.core.GraphBuilder;
import com.thalesgroup.graphFramework.core.Vertex;
import com.thalesgroup.graphFramework.core.impl.GraphBuilderImpl;
import com.thalesgroup.graphFramework.core.utils.DOTTools;

public class DepthBasedWeightsTest {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Graph<String, Void> graph;
		Serializer serializer=new Serializer();

		/* Construction */
		GraphBuilder<String, Void> b=new GraphBuilderImpl<String, Void>();
		b.createNewGraph();

		Vertex<String, Void> u=b.createVertex("u");
		Vertex<String, Void> v=b.createVertex("v");
		Vertex<String, Void> w=b.createVertex("w");
		Vertex<String, Void> x=b.createVertex("x");
		Vertex<String, Void> y=b.createVertex("y");
		Vertex<String, Void> z=b.createVertex("z");

		b.createEdge(u, v);
		b.createEdge(u, x);
		b.createEdge(v, y);
		b.createEdge(w, y);
		b.createEdge(w, z);
		b.createEdge(x, v);
		b.createEdge(x, y);
		
		b.finalizeGraph();
		graph=b.getCurrentGraph();

		//Run algorithm
		DepthBasedWeights.run(graph);

		StringBuffer buffer=new StringBuffer();
		serializer.graph2dot(graph, buffer);

		System.out.println(buffer);

	}

	static protected class Serializer extends DOTTools<String, Void> {
		@Override
		protected void feature(Vertex<String, Void> v, StringBuffer out) {
			if(v.getVertex()!=null) {
				out.append("label=\"");
				out.append(v.getVertex().toString());
				out.append("(");
				out.append(v.getUserFeature(DepthBasedWeights.depthKey));
				out.append(", ");
				out.append(v.getUserFeature(DepthBasedWeights.weightKey));
				out.append(")");
				out.append("\" ");
			}
		}
	}
}
